package com.example.youhuo.z_a_onepage.fragment

import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.module.AppGlideModule
import com.example.mvp.view.BaseFragment
import com.example.myapplication.R
import com.example.youhuo.entity.Banner_Entity
import com.example.youhuo.entity.BaseEntity
import com.example.youhuo.mvp.contract.LjlContract
import com.example.youhuo.mvp.model.LjlModel
import com.example.youhuo.mvp.presenter.LjlPresenter
import com.example.youhuo.network.HttpType
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader


class BlankFragment : BaseFragment<LjlPresenter>(),LjlContract.LjlView {
    private val appbaBanner: Banner by lazy { view1.findViewById<Banner>(R.id.appba_banner) }

    private var arrayList: ArrayList<Map<String, Any>>? = null
    private var bannerlist: ArrayList<String>? = null

    override fun findlayout(): Int {
        return R.layout.fragment_blank
    }

    override fun initView() {
        arrayList = ArrayList()
        bannerlist = ArrayList()
    }

    override fun initData() {
        myprefrag = LjlPresenter(LjlModel(), this)
        var bannermap:HashMap<String,Any>?= HashMap()
        bannermap!!.put("code", HttpType.BANNER)
        arrayList!!.add(bannermap)
        myprefrag.TabData(arrayList!!)
    }

    override fun showmsg(entity: BaseEntity) {
        if (entity is Banner_Entity){
            var bannerEntity = entity as Banner_Entity
            var values = bannerEntity.values
            for (i in 0..values!!.size-1){
                bannerlist!!.add(values[i].recommend_url.toString())
            }

            //设置图像
            appbaBanner.setImages(bannerlist)
            appbaBanner.setImageLoader(object : ImageLoader(){
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    var paths = "http://iwenwiki.com/api/yoho"+path
                    Glide.with(context).load(paths).into(imageView)
                }
            })
            appbaBanner.start()

        }
    }



}